import { getBanner } from "@/api/banner";

import { getDicts } from "@/api/system/dict/data";

const option = {
  dictName: 'rotation_map'
}

const dictList = []

/**
 * 
 * @param {Array} dicts 某类字典列表
 * @param {String} dictLabel 目标标签名称
 * @returns {Object} 根据 目标标签名称 再 字典列表中寻找到相应的元素 
 */
const  getBannerValue = (dicts, dictLabel) => {
  let findItem = dicts.find((item) => item.dictLabel === dictLabel);
  return findItem;
}


const getBannerDicts = async()=> {
  let resArr = []
  let dictsRes = await getDicts(option.dictName);
  if (dictsRes.code === 200) {
    resArr = dictsRes.data
  }
  return resArr
}

// 初始化轮播
const initBannerList = async (sourceDicts, targeLabel)=> {
  dictList = await getBannerDicts()
  let bannerValue = getBannerValue(
    sourceDicts,
    targeLabel
  );
  getBanner({ type: parseInt(bannerValue) }).then((res) => {
    if (res.code == 200) {
      this.bannerList = res.rows;
    }
  });
}